package com.zhang;

import java.util.ArrayList;
import java.util.List;

public class PageUtils {
    public static <T> List<List<T>> paginate(List<T> dataList, Integer pageSize) {
        List<List<T>> paginatedList = new ArrayList<>();
        int totalSize = dataList.size();
        for (int i = 0; i < totalSize; i += pageSize) {
            int endIndex = Math.min(i + pageSize, totalSize);
            List<T> pageData = dataList.subList(i, endIndex);
            paginatedList.add(pageData);
        }
        return paginatedList;
    }
}
